#include "Camera.h"

#ifndef PIF
#define PIF 3.141592653589793f 
#endif

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//			CONSTRUCTOR and DECON
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//=====================================================================
//		Construct Camera
//=====================================================================
BGLCamera::BGLCamera()
: m_Subject(CVector3(0,0,0)),
  m_Eye(CVector3(0,0,0)),
  m_Up(CVector3(0,0,0))
{}
//=====================================================================
//	Decompile Camera
//=====================================================================
BGLCamera::~BGLCamera()
{}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//			FUNCTIONS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//=====================================================================
//	Updates OpenGL
//=====================================================================
void BGLCamera::LookAt()
{
	gluLookAt(m_Eye.x,m_Eye.y,m_Eye.z,	m_Subject.x, m_Subject.y, m_Subject.z,	m_Up.x, m_Up.y, m_Up.z);
}
//=====================================================================
//	Rotate around target, using Up Vector as Roational Guide
//=====================================================================
void BGLCamera::Rotate(float _rotation)
{
	//------------------------------------
	//	Get View Vector
	//------------------------------------
	CVector3 _view = m_Eye - m_Subject;

    //------------------------------------
	//	Rotate the View Vector
	//------------------------------------
	_view.Rotate(_rotation,m_Up);

	//------------------------------------
	//	Add Rotated Vector
	//------------------------------------
	m_Eye = m_Subject + _view;
}
//=====================================================================
//	Rotate the camera around an axis
//=====================================================================
void BGLCamera::Rotate(float _rotation, CVector3 _axis)
{
	// TODO
}
//==============================================================
//	Rotate around an arbitary axis and point
//==============================================================
void BGLCamera::Rotate(float _rotation, CVector3 _axis, CVector3 _point)
{
	// TODO
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//			SET FUNCTIONS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//=====================================================================
//	Set Subject Vector
//=====================================================================
void BGLCamera::setSubject(CVector3 _subject)
{
	m_Subject = _subject;
}
//=====================================================================
//	Set Eye Vector
//=====================================================================
void BGLCamera::setEye(CVector3 _eye)
{
	m_Eye = _eye;
}
//=====================================================================
//	Set Up Vector
//=====================================================================
void BGLCamera::setUp(CVector3 _up)
{
	m_Up = _up;
	m_Up.Normalize();
}
//=====================================================================
//	Set Camera Vectors
//=====================================================================
void BGLCamera::set(CVector3 _subject, CVector3 _eye, CVector3 _up)
{
	m_Subject = _subject;
	m_Eye = _eye;
	m_Up = _up;
	m_Up.Normalize();
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//			ACCESSORS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//=====================================================================
//	Get Subject Vector
//=====================================================================
CVector3 BGLCamera::getSubject() const
{
	return m_Subject;
}
//=====================================================================
//	Get Eye Vector
//=====================================================================
CVector3 BGLCamera::getEye() const
{
	return m_Eye;
}
//=====================================================================
//	Get Up Vector
//=====================================================================
CVector3 BGLCamera::getUp() const
{
	return m_Up;
}